package o;

import android.graphics.Bitmap;
import android.os.Handler;
import android.os.Message;
import com.huawei.appgallery.splashscreen.impl.cache.FragmentCacheBean;
import com.huawei.appgallery.splashscreen.impl.cache.ImageCacheBean;
import com.huawei.hmf.annotation.ApiDefine;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;

@ApiDefine(uri = cyo.class)
public class cyr implements cyo, cyu {
    private static cyu ॱॱ;
    private Object ʻ;
    private boolean ʼ;
    private int ʽ = cyn.ॱ().getResources().getConfiguration().orientation;
    private boolean ˊ;
    private int ˋ;
    private cyv ˎ;
    private Bitmap ˏ;
    private cyp ˏॱ;
    private Handler ͺ = new c();
    private String ॱ;
    private int ᐝ;

    static class c extends Handler {
        WeakReference<cyr> ॱ;

        private c(cyr o_cyr) {
            this.ॱ = new WeakReference(o_cyr);
        }

        public void handleMessage(Message message) {
            cyr o_cyr = (cyr) this.ॱ.get();
            if (o_cyr != null && message.what == 1) {
                o_cyr.ͺ();
            }
        }
    }

    public cyr() {
        ˎ((cyu) this);
    }

    private static void ˎ(cyu o_cyu) {
        ॱॱ = o_cyu;
    }

    public static cyu ˏॱ() {
        return ॱॱ;
    }

    public void ˋ() {
        if (this.ͺ.hasMessages(1)) {
            cyq.ˋ.ˋ("SplashScreen", "repeat start image download!");
        } else {
            this.ͺ.sendMessageDelayed(this.ͺ.obtainMessage(1), 5000);
        }
    }

    public void ͺ() {
        cfw.ˎ(czb.ˊ(), new czf());
    }

    public boolean ˊ(boolean z) {
        ˋॱ();
        this.ᐝ = epv.ʽ(cyn.ॱ());
        this.ʼ = false;
        int ˏ = cyx.ˏ();
        if (ˏ <= 0) {
            czh.ˋ(this.ˏॱ, 1);
            return false;
        } else if (cyx.ˋ()) {
            czh.ˋ(this.ˏॱ, 3);
            cyq.ˋ.ˏ("SplashScreen", "language or region change,clear image cache.");
            return false;
        } else {
            this.ˊ = z;
            ˎ(ˏ);
            return ॱˊ();
        }
    }

    private void ˎ(int i) {
        List ˋ = ˋ(i);
        int i2 = 0;
        while (i2 < ˋ.size()) {
            if (((Integer) ˋ.get(i2)).intValue() >= 0 && ((Integer) ˋ.get(i2)).intValue() < i) {
                int intValue = ((Integer) ˋ.get(i2)).intValue();
                cyv ॱ = cyx.ॱ(intValue);
                if (ॱ == null) {
                    cyq.ˋ.ˏ("SplashScreen", "imageCache == null");
                } else {
                    ImageCacheBean ॱ2 = ॱ.ॱ();
                    if (ॱ2.ˏॱ() != this.ᐝ) {
                        this.ʼ = true;
                        return;
                    }
                    Object ˏ = cyw.ॱ().ˏ(ॱ2);
                    if (ˏ != null) {
                        this.ˎ = ॱ;
                        this.ˋ = intValue;
                        this.ʻ = ˏ;
                        if (ॱ.ॱ().ˊ() == 0) {
                            if (ˏ instanceof Bitmap) {
                                this.ˏ = (Bitmap) ˏ;
                            }
                        } else if (ˏ instanceof String) {
                            this.ॱ = (String) ˏ;
                        }
                        cyx.ˊ(intValue);
                        return;
                    }
                }
            }
            i2++;
        }
    }

    private List<Integer> ˋ(int i) {
        List<Integer> arrayList = new ArrayList();
        if (this.ˊ) {
            arrayList.add(Integer.valueOf(cyx.ᐝ()));
            return arrayList;
        }
        int ˎ = cyz.ˎ(i);
        if (ˎ == -1) {
            cyq.ˋ.ˋ("SplashScreen", "sequence selection");
            return cza.ˊ(i);
        }
        cyq.ˋ.ˋ("SplashScreen", "random selection");
        arrayList.add(Integer.valueOf(ˎ));
        return arrayList;
    }

    private boolean ॱˊ() {
        if (this.ʻ != null) {
            this.ʽ = cyn.ॱ().getResources().getConfiguration().orientation;
            return true;
        }
        if (this.ʼ) {
            czh.ˋ(this.ˏॱ, 4);
        } else {
            czh.ˋ(this.ˏॱ, 2);
        }
        return false;
    }

    public void ˎ(cyp o_cyp) {
        this.ˏॱ = o_cyp;
    }

    private void ˊॱ() {
        int i = 1;
        if (this.ˎ != null && !this.ˊ) {
            ImageCacheBean ॱ = this.ˎ.ॱ();
            long currentTimeMillis = System.currentTimeMillis();
            long ˎ = czh.ˎ(ॱ);
            int ʼ = czh.ʼ(ॱ);
            if (ˎ <= 0) {
                ˎ = currentTimeMillis;
            } else {
                long ʻ = czh.ʻ(ॱ);
                int ʽ = czh.ʽ(ॱ);
                if (ʻ > 0 && ʽ > 0) {
                    if (currentTimeMillis - ˎ >= ʻ) {
                        ˎ = currentTimeMillis;
                    } else if (ʼ < ʽ) {
                        i = ʼ + 1;
                    }
                }
                i = ʼ;
            }
            ॱ.ˊ(ˎ);
            ॱ.ˎ(i);
            ॱ.ˎ(currentTimeMillis);
            this.ˎ.ˊ(ॱ);
            cyx.ॱ(this.ˎ, this.ˋ);
        }
    }

    public void ˏ() {
        ˊॱ();
    }

    public FragmentCacheBean ˊ() {
        if (this.ˎ != null) {
            return this.ˎ.ˏ();
        }
        return null;
    }

    public boolean ˎ() {
        return this.ˊ;
    }

    public int ᐝ() {
        return this.ʽ;
    }

    public int ʽ() {
        return this.ᐝ;
    }

    public Bitmap ॱ() {
        return this.ˏ;
    }

    public void ʻ() {
        ˋॱ();
    }

    public cyp ॱॱ() {
        return this.ˏॱ;
    }

    public String ʼ() {
        return this.ॱ;
    }

    private void ˋॱ() {
        this.ˎ = null;
        this.ˋ = 0;
        this.ˊ = false;
        this.ˏ = null;
        this.ʻ = null;
        this.ॱ = null;
    }
}
